docs: document waitForResponse recipe for deferred mutations#30
Merged
Conversation
The standard Next.js App Router transition (startTransition + Server Action + router.refresh()) dispatches its request a tick after the action returns, so settleUntil: 'networkidle' can resolve against the pre-mutation UI. When there's no committed DOM signal to name for waitFor but the request behind the change is identifiable, arm page.waitForResponse(...) before the action and await it — it can't resolve until the matching request has fired and returned, closing the gap with no settleMs guess. Adds the recipe to the deferred-mutation warning, reframes the three reliable options in precedence order (DOM signal > endpoint > network quiet), and updates the settling rule-of-thumb. Resolves #24 in favor of guidance over a new settleUntil: 'mutation' heuristic. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #24.
What
Documents the
page.waitForResponse(...)recipe as the reliable path for the standard Next.js App Router transition (startTransition+ Server Action +router.refresh()), wheresettleUntil: 'networkidle'can race the deferred dispatch and settle on the pre-mutation UI.The recipe arms the response wait before the action and awaits it after — it can't resolve until the matching request has fired and returned, closing the transition gap with no
settleMsguess. Placement insiderun()is required (waitForruns too late to arm the listener).Changes (docs-only,
docs/writing-tutorials.md)waitForResponserecipe to the deferred-mutation warning blockquote.waitFor) > known endpoint (waitForResponse) > network quiet (settleUntil: 'networkidle', now reserved for when you have neither).waitForResponserow to the Settling table and scoped thesettleUntilrow accordingly, so the table and prose agree.Why guidance over code
Resolves #24 in favor of documentation rather than a new
settleUntil: 'mutation'heuristic, per the issue's own "revisit only if the guidance proves insufficient in real authoring" framing. A request-aware heuristic would trade one subtle race (pre-mutation transient) for another (settling early on background polling, or hanging when a mutation fires no request). Consumers can drop theirsettleMsworkarounds using the documented recipe with no release.Review
Reviewed by the code-reviewer agent: recipe is technically sound (correct
waitForResponsesignature, arm-before/await-after pattern genuinely closes the gap), prose/fences/anchors clean. The one flagged consistency gap (table still steering known-endpoint cases tonetworkidle) was fixed before push.🤖 Generated with Claude Code